package com.xrit.sunnyday.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.xrit.sunnyday.dao.MemberMobileDao;
import com.xrit.sunnyday.pojo.Member;
import com.xrit.sunnyday.service.MemberMobileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@Transactional
@Service(interfaceClass = MemberMobileService.class)
public class MemberMobileServiceImpl implements MemberMobileService {
    @Autowired
    private MemberMobileDao memberMobileDao;

    /**
     * 通过手机号码查询会员信息
     */
    @Override
    public Member findByTelephone(String telephone) {
        return memberMobileDao.findBytelephone(telephone);
    }

    @Override
    public void add(Member member) {
        memberMobileDao.add(member);
    }

    @Override
    public List<Integer> getMemberReport(List<String> months) {
        //建一个集合存储去年每个月的会员注册数量
        List<Integer> memberCount = new ArrayList<>();
        //遍历查询
        for (int i = 0; i < months.size(); i++) {
            int count = memberMobileDao.getMemberReport(months.get(i));
            //添加到集合
            memberCount.add(count);
        }
        return memberCount;
    }

    @Override
    public List<Map<String, Object>> getSetmealReport() {
        return memberMobileDao.getSetmealReport();
    }
}
